# -*- coding=utf-8-*-
"""
@File:memory_selection
@Author:Created by Han X.Y
@Date:on 2021/8/4 11:18 
"""
class Node:
    """
    定义树节点
    """
    def __init__(self,value=None,left=None,right=None):
        self.value=value
        self.left=left#左子树
        self.right=right#右子树


def preTraverse(root):
    """
    前向遍历
    先根节点，后左子树、后右子树
    Args:
        root:

    Returns:

    """
    if root==None:
        return
    print(root.value)
    preTraverse(root.left)
    preTraverse(root.right)


def midTraverse(root):
    """
    中序遍历
    Args:
        root:

    Returns:

    """
    if root is None:
        return
    midTraverse(root.left)
    print(root.value)
    midTraverse(root.right)


def afterTraverse(root):
    """
    后序遍历
    Args:
        root:

    Returns:

    """
    if root is None:
        return
    afterTraverse(root.left)
    afterTraverse(root.right)
    print(root.value)


if __name__ =="__main__":
    root=Node('D',Node('B',Node("A"),Node('C')),Node('E',right=Node('G',Node('F'))))
    print('前序遍历:\n')
    preTraverse(root)
    print('\n')
    print('中序遍历：\n')
    midTraverse(root)
    print('\n')
    print('后续遍历：\n')
    afterTraverse(root)
    print('\n')